#ifndef __IO_MILC_V5_H__
#define __IO_MILC_V5_H__

/*
  Synopsis of MILC v5 binary data formats
  =======================================

  SU(3) gauge field file layout:
  ------------------------------
   MILC_v5_gauge_header
  [IO_site_order_list] (parallel IO)
   MILC_check32
   SU(3) matrices (32-bit float only!)

  Wilson quark field file layout:
  -------------------------------
   MILC_v5_wquark_header
  [IO_site_order_list] (parallel IO)
   MILC_v5_wquark_rec_header
   Quark data (float only!)
  [MILC_v5_wquark_rec_header
   Quark data (float only!)
   ...
  ]
*/

#include <io_common.h>

#define MAX_TIME_STAMP 64
#define MILC_V5_GAUGE  20103
#define MILC_V5_W_PROP 12781
#define MAX_SOURCE_SPINS 4

typedef struct {
  IO_type32 magic_number;
  IO_type32 dim[4];
  char   timestamp[MAX_TIME_STAMP];
  IO_type32 site_order;
} MILC_v5_gauge_header;

typedef struct {
  IO_type32 magic_number;
  IO_type32 dim[4];
  char   timestamp[MAX_TIME_STAMP];
  IO_type32 site_order;
  IO_type32 n_src_spins;
  IO_type32 src_spin_list[MAX_SOURCE_SPINS];
} MILC_v5_wquark_header;

typedef struct {
  IO_type32u sum29;
  IO_type32u sum31;
} MILC_check32;

typedef struct {
  IO_type32 spin;
  IO_type32 color;
  MILC_check32 check;
} MILC_v5_wquark_rec_header;

typedef struct {
  int n_spin;
  MILC_v5_wquark_rec_header header[MAX_SOURCE_SPINS][3];
} MILC_v5_wquark_directory;


int MILC_v5_read_gauge_header ( IO_filehand* fh,
				MILC_v5_gauge_header* header );

void MILC_v5_print_gauge_header ( FILE* fp, MILC_v5_gauge_header* header );

int MILC_read_checksum ( IO_filehand* fh, MILC_check32* check );

int MILC_v5_read_wquark_file_header ( IO_filehand* fh,
				     MILC_v5_wquark_header* header );

int MILC_v5_read_wquark_rec_header ( IO_filehand* fh,
				    MILC_v5_wquark_rec_header* header );

void MILC_v5_print_wquark_file_header ( FILE* out,
				       MILC_v5_wquark_header* header );

void MILC_v5_print_wquark_rec_header ( FILE* out,
				      MILC_v5_wquark_rec_header* header );

void MILC_v5_print_wquark_dir ( FILE* out, MILC_v5_wquark_directory* dir );

int MILC_v5_build_wquark_dir ( IO_filehand* fh,
			       MILC_v5_wquark_header* fheader,
			       MILC_v5_wquark_directory* dir );

int MILC_v5_seek_wquark ( IO_filehand* fh, MILC_v5_wquark_header* fheader,
			  int src_spin, int src_color, int t );

int MILC_read_site_data32 ( IO_filehand* fh, int nelem, void* site_data );

#endif
